﻿import img2;
import requests;
import re;
from PIL import Image, ImageDraw, ImageFont
from io import BytesIO;
class tp():

	def getHtml(url):

		# url ='https://www.aitaotu.com/dmtp/hzw/36245.html';

		r = requests.get(url = url);

		htmlT= r.text 

		pattern = re.compile(r'(?<="title": ").+(?=",)|(?<="images": \[ ").+(?=" ])|(?<="description": ").+(?=",)|(?<=totalpage">)\d+')   # 查找数字

		result1 = pattern.findall(htmlT)


		t = open('tui.txt','w+', encoding='utf8');

		t.write(htmlT);

		return result1

	def srcImg(img_src,sela = 5):

		response = requests.get(img_src)

		head = Image.open(BytesIO(response.content)) #头像

		head_size=head.size

		head=head.resize((round(head_size[0]/sela),round(head_size[1]/sela)))

		return head

	def pic_save(image,filename):
		#保存
		image.save(filename)

	def forPic(self,url):

		picUrl = tp.getHtml(url)

		iurl = picUrl[1]

		print(iurl)

		pic = self.srcImg(img_src=iurl,sela=2)

		self.pic_save(image=pic,filename=picUrl[0] + '.jpg')



if __name__ == '__main__':

	tp.forPic(self = tp,url='https://www.aitaotu.com/dmtp/hzw/36245.html')

	#pic = tp.srcImg(img_src='https://pics0.baidu.com/feed/b151f8198618367ac2ecf333d01db5d3b21ce569.jpeg?token=9c3e1c10406aca490a8f8603459cc206',sela=2)

	#tp.pic_save(image=pic,filename='草莓.jpg')